#include "precomp.h"
#include <ServerEngine/Engine.h>
#include <ServerEngine/Script/ScriptSystem.h>
#include <ServerEngine/File/FileSystem.h>
#include <ServerEngine/Network/NetSystem.h>

using namespace TSE;

Engine &Engine::ref()
{
	static Engine instance;
	return instance;
}

Engine::Engine()
: file(0x0), script(0x0)
{
	file = new FileSystem(*this);
	script = new ScriptSystem(*this);

	expose();
}

Engine::~Engine()
{
	if(file)
		delete file;
	if(script)
		delete script;
}

void Engine::Main(int argc, char *argv[])
{
	script->Main(argc, argv);
}

void Engine::tick(double dt)
{
}

///////////////////////////////
// FILE SYSTEM
///////////////////////////////
CL_String Engine::getRootPath()
{
	return file->getRootPath();
}

///////////////////////////////
// SCRIPT SYSTEM
///////////////////////////////
void Engine::runScript(const CL_String &script)
{
	this->script->runString(script);
}
void Engine::runScript(const CL_String &rel_path, const CL_String &filename)
{
	script->runFile(rel_path, filename);
}
void Engine::expose()
{
	//Expose the different sub-systems
	NetSystem::Expose();
}

///////////////////////////////
// NETWORK SYSTEM
///////////////////////////////
bool Engine::dispatch(const CL_String &line, IConnection *connection)
{
	return true;
}

int Engine::login(const CL_String &username, const CL_String &password)
{
	return 0;
}
